package com.sgcc.activiti.controller;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.sgcc.common.log.annotation.Log;
import com.sgcc.common.log.enums.BusinessType;
import com.sgcc.common.security.annotation.PreAuthorize;
import com.sgcc.activiti.domain.OAnomalyTypeDuration;
import com.sgcc.activiti.service.IOAnomalyTypeDurationService;
import com.sgcc.common.core.web.controller.BaseController;
import com.sgcc.common.core.web.domain.AjaxResult;
import com.sgcc.common.core.utils.poi.ExcelUtil;
import com.sgcc.common.core.web.page.TableDataInfo;

/**
 * OAnomalyTypeDurationController
 * 
 * @author sgcc
 * @date 2021-04-09
 */
@RestController
@RequestMapping("/OAnomalyTypeDuration")
public class OAnomalyTypeDurationController extends BaseController
{
    @Autowired
    private IOAnomalyTypeDurationService oAnomalyTypeDurationService;

    /**
     * 查询OAnomalyTypeDuration列表
     */
    //@PreAuthorize(hasPermi = "activiti:OAnomalyTypeDuration:list")
    @GetMapping("/list")
    public TableDataInfo list(OAnomalyTypeDuration oAnomalyTypeDuration)
    {
        startPage();
        List<OAnomalyTypeDuration> list = oAnomalyTypeDurationService.selectOAnomalyTypeDurationList(oAnomalyTypeDuration);
        return getDataTable(list);
    }

    /**
     * 导出OAnomalyTypeDuration列表
     */
    //@PreAuthorize(hasPermi = "activiti:OAnomalyTypeDuration:export")
    @Log(title = "OAnomalyTypeDuration", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OAnomalyTypeDuration oAnomalyTypeDuration) throws IOException
    {
        List<OAnomalyTypeDuration> list = oAnomalyTypeDurationService.selectOAnomalyTypeDurationList(oAnomalyTypeDuration);
        ExcelUtil<OAnomalyTypeDuration> util = new ExcelUtil<OAnomalyTypeDuration>(OAnomalyTypeDuration.class);
        util.exportExcel(response, list, "OAnomalyTypeDuration");
    }

    /**
     * 获取OAnomalyTypeDuration详细信息
     */
    //@PreAuthorize(hasPermi = "activiti:OAnomalyTypeDuration:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(oAnomalyTypeDurationService.selectOAnomalyTypeDurationById(id));
    }

    /**
     * 新增OAnomalyTypeDuration
     */
    //@PreAuthorize(hasPermi = "activiti:OAnomalyTypeDuration:add")
    @Log(title = "OAnomalyTypeDuration", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OAnomalyTypeDuration oAnomalyTypeDuration)
    {
        return toAjax(oAnomalyTypeDurationService.insertOAnomalyTypeDuration(oAnomalyTypeDuration));
    }

    /**
     * 修改OAnomalyTypeDuration
     */
    //@PreAuthorize(hasPermi = "activiti:OAnomalyTypeDuration:edit")
    @Log(title = "OAnomalyTypeDuration", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Map map) throws Exception {
        if (map.size() < 0){
            return AjaxResult.error(201,"缺少参数！");
        }
        List<OAnomalyTypeDuration> oAnomalyTypeDurationList = (List<OAnomalyTypeDuration>)map.get("oAnomalyTypeDurationList");
        return toAjax(oAnomalyTypeDurationService.updateOAnomalyTypeDuration(oAnomalyTypeDurationList));
    }

    /**
     * 删除OAnomalyTypeDuration
     */
    //@PreAuthorize(hasPermi = "activiti:OAnomalyTypeDuration:remove")
    @Log(title = "OAnomalyTypeDuration", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(oAnomalyTypeDurationService.deleteOAnomalyTypeDurationByIds(ids));
    }
}
